import yaml
from registry.authentication import Auth

def readConfig() -> dict:
    """
    读取配置文件
    result:
        {
            "host": "
            "user": "
            "passwd": "
            "https": "
        }
    return:
        dict
    ymlfile:
        config.yml
    yml:
        host: " "   # 仓库地址
        user: " "   # 用户名
        passwd: " " # 密码
        https: " "  # 是否启用https
    """
    with open("config.yml", 'r') as ymlfile:
        cfg = yaml.load(ymlfile, Loader=yaml.Loader)
    return cfg

def getConfigAuth() -> Auth:
    cfg = readConfig()
    if cfg["host"] is None:
        return None
    if cfg["https"] is None:
        cfg["https"] = False
    return Auth(cfg["host"], cfg["user"], cfg["passwd"], cfg["https"])

def getAuth(cfg: dict) -> Auth:
    if cfg["host"] is None:
        return None
    if cfg["https"] is None:
        cfg["https"] = False
    return Auth(cfg["host"], cfg["user"], cfg["passwd"], cfg["https"])

